﻿#ifndef CHART_H
#define CHART_H

#include <QtCharts>
#include <QWidget>
#include <QtWidgets>

QT_CHARTS_BEGIN_NAMESPACE
class QSplineSeries;
class QLineSeries;
class QValueAxis;
QT_CHARTS_END_NAMESPACE

#include <QObject>

class Chart :public QChart
{
    Q_OBJECT
public:
    Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
    virtual ~Chart();

    void slt_dtuRouteSwtich(int route_id, bool checked);

    QSplineSeries *m_series[4];
    QValueAxis *m_axisX;
    QValueAxis *m_axisY;
    qreal m_step;
    qreal m_x;
    qreal scroll_step, axis_step;

//public slots:
    void slt_updateChart(const QList<int>& data);
};

class ChartManager : public QObject
{
    Q_OBJECT
public:
    ChartManager(QChartView* tableView = nullptr);
    ~ChartManager();
    void addDTU(uint id);
    Chart* currentChart() {return curChart; }
    //Chart* id2Chart(uint id) {return chartlist[id];}
    void updateChart(uint id, const QList<int>& data);

public slots:
    void slt_dtuRouteSwtich(int route_id, bool checked);
    void slt_dtuSwitch(uint id);

private:
    QHash<uint, Chart*> chartlist;
    Chart* curChart;
    QChartView* chartView;
};

class HisChart : public QChart
{
    Q_OBJECT
public:
    HisChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
    virtual ~HisChart();

    void slt_updateSeries(const QList<QVector<QPointF>>& currents);
    void slt_dtuRouteSwtich(int route_id, bool checked);

    QSplineSeries *m_series[4];
    QValueAxis *m_axisX;
    QValueAxis *m_axisY;
};


#endif // CHART_H
